/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ApplicationChooser.java
 *
 * Created on 18.12.2011., 16.27.47
 */

package universaldistributedsystem.appchooser;

import javax.swing.JOptionPane;

/**
 *
 * @author Nemanja
 */
public class ApplicationChooser extends javax.swing.JFrame implements Runnable{

    /** Creates new form ApplicationChooser */
    public ApplicationChooser() {
        initComponents();
        setLocationRelativeTo(null);
        //jButtonServer.setIcon(new ImageIcon("universaldistributedsystem/server/resources/server_icon.png"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonServer = new javax.swing.JButton();
        jButtonWorkstation = new javax.swing.JButton();
        jButtonClient = new javax.swing.JButton();
        jButtonExit = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Application chooser");
        setResizable(false);

        jButtonServer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/universaldistributedsystem/server/resources/server_icon.png"))); // NOI18N
        jButtonServer.setText("Server");
        jButtonServer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonServerActionPerformed(evt);
            }
        });

        jButtonWorkstation.setIcon(new javax.swing.ImageIcon(getClass().getResource("/universaldistributedsystem/workstation/resources/workstation_icon.png"))); // NOI18N
        jButtonWorkstation.setText("Workstation");
        jButtonWorkstation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonWorkstationActionPerformed(evt);
            }
        });

        jButtonClient.setIcon(new javax.swing.ImageIcon(getClass().getResource("/universaldistributedsystem/client/resources/client_icon.png"))); // NOI18N
        jButtonClient.setText("Client");
        jButtonClient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonClientActionPerformed(evt);
            }
        });

        jButtonExit.setText("Exit");
        jButtonExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonServer)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonWorkstation)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonClient))
                    .addComponent(jButtonExit, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonServer)
                    .addComponent(jButtonWorkstation)
                    .addComponent(jButtonClient))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonExit)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonWorkstationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonWorkstationActionPerformed
        callWorkstation();
    }//GEN-LAST:event_jButtonWorkstationActionPerformed

    private void jButtonServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonServerActionPerformed
        callServer();
    }//GEN-LAST:event_jButtonServerActionPerformed

    private void jButtonExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jButtonExitActionPerformed

    private void jButtonClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonClientActionPerformed
        //JOptionPane.showMessageDialog(null, "Not implemented.");
        callClient();
    }//GEN-LAST:event_jButtonClientActionPerformed

    private static String appStarter = "";

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        if(args.length > 0)
            ApplicationChooser.appStarter = args[0];
        /*java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                if(ApplicationChooser.appStarter.equalsIgnoreCase("server")){

                }else if(ApplicationChooser.appStarter.equalsIgnoreCase("workstation")){

                }else if(ApplicationChooser.appStarter.equalsIgnoreCase("client")){
                    
                }else
                    new ApplicationChooser().setVisible(true);
            }
        });*/
        java.awt.EventQueue.invokeLater(new ApplicationChooser());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonClient;
    private javax.swing.JButton jButtonExit;
    private javax.swing.JButton jButtonServer;
    private javax.swing.JButton jButtonWorkstation;
    // End of variables declaration//GEN-END:variables

    private void callServer(){
        setVisible(false);
        universaldistributedsystem.server.ServerGUI.main(null);
    }

    private void callWorkstation(){
        //new ApplicationChooser().setVisible(true);
        JOptionPane.showMessageDialog(null, "Not implemented.");
        System.exit(0);
    }

    private void callClient(){
        setVisible(false);
        universaldistributedsystem.client.ClientGUI.main(null);
    }

    public void run() {
        //throw new UnsupportedOperationException("Not supported yet.");
                if(ApplicationChooser.appStarter.equalsIgnoreCase("server"))
                {
                    callServer();
                }
                else if(ApplicationChooser.appStarter.equalsIgnoreCase("workstation"))
                {
                    callWorkstation();
                }
                else if(ApplicationChooser.appStarter.equalsIgnoreCase("client"))
                {
                    callClient();
                }
                else
                    new ApplicationChooser().setVisible(true);


    }
}
